﻿using System.Management.Automation;
using DotNet.DevOps.Tasks.Oracle;

namespace DotNet.DevOps.Cmdlets
{
    [Cmdlet(VerbsCommon.Push, "OracleScript", ConfirmImpact = ConfirmImpact.High, SupportsShouldProcess = false, SupportsTransactions = false)]
    public class Push_OracleScript : Cmdlet
    {
        [Parameter(Mandatory = true, Position = 0)]
        public string Files { get; set; }
        [Parameter(Mandatory = true, Position = 1)]
        public string Database { get; set; }
        [Parameter(Mandatory = true, Position = 2)]
        public string User { get; set; }
        [Parameter(Mandatory = true, Position = 3)]
        public string Password { get; set; }
        [Parameter(Mandatory = false, Position = 4)]
        public bool FailOnLogonError { get; set; }
        [Parameter(Mandatory = false, Position = 5)]
        public bool FailOnScriptError { get; set; }
        [Parameter(Mandatory = false, Position = 6)]
        public int Timeout { get; set; }

        private IOracleScript task;

        protected override void BeginProcessing()
        {
            task = new OracleScript(new PowershellCmdletLogger(this))
            {
                Files = Files,
                Database = Database,
                User = User,
                Password = Password,
                FailOnLogonError = FailOnLogonError,
                FailOnScriptError = FailOnScriptError,
                Timeout = Timeout
            };
        }

        protected override void ProcessRecord()
        {
            task.Execute();
        }
    }
}
